<?php
require '../../common/initPage.php';
require '../../common/dbcon.php';
require '../../common/func.php';
require '../../common/showTips.php';
require '../../common/checkForm.php';

session_start();
//拦截未登录
filterLogout();

if (empty($_GET['show'])) {
    unset($_SESSION['actionUserShowTips']);
}

$pageNow = $_GET['pagenow'];
$_SESSION['userListPageNow'] = $_GET['pagenow'];
$rempagenow = $_SESSION['userListPageNow'];

$searchValue = $_GET['searchvalue'];
$_SESSION['userListSearchvalue'] = $_GET['searchvalue'];
$remsearchvalue = $_SESSION['userListSearchvalue'];

if ($_GET['action'] == 'lock') {
    if (uplockUser($mysqlCon, updateUserisLock, $_GET['lockid'])) {
        $_SESSION['actionUserShowTips'] = '封禁用户 ' . $_GET['lockname'] . ' 成功';
        $_SESSION['actionUsertipsType'] = 'success';
    } else {
        $_SESSION['actionUserShowTips'] = '封禁用户 ' . $_GET['lockname'] . ' 失败';
        $_SESSION['actionUsertipsType'] = 'danger';
    }
} elseif ($_GET['action'] == 'unlock') {
    if (uplockUser($mysqlCon, updateUserisLock, $_GET['unlockid'])) {
        $_SESSION['actionUserShowTips'] = '解封用户 ' . $_GET['unlockname'] . ' 成功';
        $_SESSION['actionUsertipsType'] = 'success';
    } else {
        $_SESSION['actionUserShowTips'] = '解封用户 ' . $_GET['unlockname'] . ' 失败';
        $_SESSION['actionUsertipsType'] = 'danger';
    }
}

if ($_GET['action'] == 'delete') {
    if (deleteUser($mysqlCon, deleUser, $_GET['delid'])) {
        $_SESSION['actionUserShowTips'] = '删除用户 ' . $_GET['delname'] . ' 成功';
        $_SESSION['actionUsertipsType'] = 'success';
    } else {
        $_SESSION['actionUserShowTips'] = '删除用户 ' . $_GET['delname'] . ' 失败';
        $_SESSION['actionUsertipsType'] = 'danger';
    }
}

$showFlag = $_SESSION['loginIden'] == '管理员';
if ($showFlag) {
    $querycate = '';
} else {
    $querycate = 5;
}
$ListTotal = queryAll($mysqlCon, queryAllexLoginNum, $_SESSION['loginId'], $querycate, $searchValue);
$pageTotal=pageFunc($ListTotal);
$userList = queryAllexLU($mysqlCon, queryAllexLogin, $_SESSION['loginId'], $querycate, $searchValue, $pageNow);
$routerUrl = '../../views/public/userList.html';

if($showFlag){
    require '../../views/admin/template.html';
}else{
    require '../../views/user/template.html';
}